package model.eval;

import enums.PremisaTypeEnum;
import enums.TestPanelEnum;
import enums.TextBundleEnum;
import enums.URLEnum;
import misc.BundlesProvider;
import model.Sylogism;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * @author Jose Martin Rozanec;
 */
public class TestExerciseSylogismFromParameters extends TestExcercise {

    /**
     * Constructor;
     */
    public TestExerciseSylogismFromParameters() {
        this.panelEnum = TestPanelEnum.CREAR_SILOGISMO;
    }

    public int getAchievedScore() {
        SylogismData data = (SylogismData) getExcerciseData();
        Sylogism sylogism = (Sylogism) getStudentsSolution();
        boolean correct = true;
        if (data.pideTerminos()) {
            if (data.getTerminoMayor() != null) {
                correct = correct && data.getTerminoMayor().equalsIgnoreCase(sylogism.getTerminoMayor());
            }
            if (data.getTerminoMedio() != null) {
                correct = correct && data.getTerminoMedio().equalsIgnoreCase(sylogism.getTerminoMedio());
            }
            if (data.getTerminoMenor() != null) {
                correct = correct && data.getTerminoMenor().equalsIgnoreCase(sylogism.getTerminoMenor());
            }
        }
        if (data.pideExtension()) {
            if (data.getPremisaMayorExtension() != null) {
                correct = correct && data.getPremisaMayorExtension().equals(sylogism.getPremisa(PremisaTypeEnum.FIRST).getPartsExtension());
            }
            if (data.getPremisaMenorExtension() != null) {
                correct = correct && data.getPremisaMenorExtension().equals(sylogism.getPremisa(PremisaTypeEnum.SECOND).getPartsExtension());
            }
            if (data.getConclusionExtension() != null) {
                correct = correct && data.getConclusionExtension().equals(sylogism.getPremisa(PremisaTypeEnum.CONCLUSION).getPartsExtension());
            }
        }
        if (data.pideFigura()) {
            if (data.getFigura() != null) {
                System.out.println("" + (data.getFigura() == (sylogism.getFigure())));
                System.out.println("" + (data.getFigura().equals(sylogism.getFigure())));
                correct = correct && data.getFigura() == (sylogism.getFigure());
            }
        }

        if (correct) {
            return getCorrectScore();
        } else {
            return getIncorrectScore();
        }
    }

    public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append(
                BundlesProvider.getBundle(URLEnum.TEXT_BUNDLE).getString(TextBundleEnum.CREAR_SILOGISMO.toString()));
        buffer.append(" [" + getCorrectScore() + "] [" + getIncorrectScore() + "]\n");
        buffer.append(((SylogismData) getExcerciseData()).toString());
        return buffer.toString();
    }

    public String getStudentSolutionString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append(
                BundlesProvider.getBundle(URLEnum.TEXT_BUNDLE).getString(TextBundleEnum.CREAR_SILOGISMO.toString()));
        buffer.append(" [" + getCorrectScore() + "] [" + getIncorrectScore() + "]\n");
        buffer.append("> " +
                BundlesProvider.getBundle(
                        URLEnum.TEXT_BUNDLE).getString(TextBundleEnum.EXCERCISE.toString()) + ":\n");
        buffer.append(getExcerciseData().toString());
        buffer.append("> " +
                BundlesProvider.getBundle(
                        URLEnum.TEXT_BUNDLE).getString(TextBundleEnum.RESOLUCION.toString()) + ":\n");
        if (getStudentsSolution() != null) {
            buffer.append((((Sylogism) getStudentsSolution()).toString()));
        }

        return buffer.toString();
    }
}

